package com.bbtShop.api;

import com.bbtShop.aop.Login;
import com.bbtShop.core.model.*;
import com.bbtShop.dao.ProductViewMapper;
import com.bbtShop.service.ProductCategoryService;
import com.bbtShop.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : manke
 * @Description
 * @Date: 2020/10/18 19:06
 */
@Api(value = "ProductController", description = "产品控制器")
@RestController
@RequestMapping("/Product")
public class ProductController {


    @Autowired
    private ProductService productService;

    @ApiOperation(value = "getLisProduct", notes = "获取产品列表")
    @PostMapping("/getLisProduct")
    @Login(permission = "Product:getLisProduct")
    public ApiResponse<Object> getLisProduct(@RequestParam(required = false) Integer pageNum,
                                             @RequestParam(required = false) Integer pageSize,
                                             @RequestBody ProductView productView) {
        return ApiResponse.success(productService.getLisProduct(pageNum, pageSize, productView));
    }

    @ApiOperation(value = "addUpdateProduct", notes = "添加修改产品")
    @PostMapping("/addUpdateProduct")
    @Login(permission = "Product:addUpdateProduct")
    public ApiResponse<Object> addUpdateProduct(@RequestBody Product product) {
        productService.addUpdateProduct(product);
        return ApiResponse.success();
    }

    @ApiOperation(value = "delProduct", notes = "删除产品")
    @PostMapping("/delProduct")
    @Login(permission = "Product:delProduct")
    public ApiResponse<Object> delProduct(@RequestBody Ids ids) {
        productService.delProduct(ids);
        return ApiResponse.success();
    }



    @ApiOperation(value = "getProductInfo", notes = "获取产品详情信息")
    @GetMapping("/getProductInfo")
    @Login(permission = "Product:getProductInfo")
    public ApiResponse<Product> getProductInfo(@RequestParam Integer id) {
        return ApiResponse.success(productService.getProductInfo(id));
    }

    @ApiOperation(value = "getAllProductId", notes = "获取所有产品")
    @GetMapping("/getAllProductId")
    @Login(permission = "Product:getAllProductId")
    public ApiResponse<List<Product>> getAllProduct() {
        return ApiResponse.success(productService.getAllProductId());
    }


}
